package com.innovations.web.controller.system;

import com.innovations.common.core.controller.BaseController;
import com.innovations.common.core.domain.AjaxResult;
import com.innovations.framework.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 短信发送
 *
 * @author dp
 */
@Api(tags = "短信发送")
@RestController
@RequestMapping("/system/sms")
public class SysSmsController extends BaseController {
    @Autowired
    SmsService smsService;

    @ApiOperation("发送短信验证码")
    @GetMapping("/verification")
    public AjaxResult verification(@RequestParam("phoneNumber") String phoneNumber) {

        return AjaxResult.success(smsService.sendVerification(phoneNumber));
    }

    @ApiOperation("发送业务通知短信")
    @PostMapping("/notification")
    public AjaxResult notification(String phone, String templateId, Map<String, String> params) {

        return AjaxResult.success(smsService.sendNotification(phone, templateId, params));
    }

    @ApiOperation("核验短信验证码")
    @PostMapping("/verification/check")
    public AjaxResult checkVerificationCode(@RequestParam("phoneNumber") String phoneNumber ,@RequestParam("code") String code) {
      boolean result =  smsService.checkVerificationCode(phoneNumber, code);
      return result ? AjaxResult.success() : AjaxResult.error();
    }

}
